using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using FBGraph.Models;
using FBGraph.Web.Mvc;

namespace FBGraph.Demos.AspNetMvc.Controllers
{
    [FBGraphAuthorize(ExtendedPermission.ReadStream)]
    public class StreamController : BaseController
    {
        public ActionResult Index()
        {
            var feed = FbContext.Feed.GetFor("me");

            return View(feed);
        }

        public ActionResult Like(String id)
        {
            this.FbContext.Posts.Like(id);

            return RedirectToAction("Index");
        }

        public ActionResult Unlike(String id)
        {
            this.FbContext.Posts.Unlike(id);

            return RedirectToAction("Index");
        }

        [FBGraphAuthorize(ExtendedPermission.PublishStream)]
        public ActionResult PostSomething()
        {
            var result = this.FbContext.Feed.Write(null, "I made this post using FBGraph.NET!", "http://dandoes.net/Content/bracket-top-left.png",
                "http://fbgraph.codeplex.com", "FBGraph.NET", "The only, and therefore the BEST Graph API client for .NET!");

            var parts = result.ToString().Split('_');

            return Redirect(String.Format("http://www.facebook.com/#!/profile.php?id={0}&v=wall&story_fbid={1}", parts));
        }

        public ActionResult Comment(Comment comment)
        {
            var result = this.FbContext.Comments.Create(comment.Id, comment.Message);

            var parts = result.ToString().Split('_');

            return Redirect(String.Format("http://www.facebook.com/#!/profile.php?id={0}&v=wall&story_fbid={1}", parts));
        }
    }
}